package Qieces;

import java.awt.*;

/**
 * 卒类
 *
 */
public class Soldier extends Qiece{

    public Soldier(Qiece a,int index,int c){

        if (index == 0){
            this.kind = 7;
            this.x = a.x;
            this.y = a.y;
            this.controller = c;
            this.moveof = 0;
        }else if (index == 1){
            this.kind = a.kind;
            this.controller = a.controller;
        }
        this.scl = 0;
    }

    @Override
    public void paintSelf(Graphics g) {
        if(this.controller == 0 && this.kind !=0){           //为黑子时
            g.drawImage(soldier_b,x,y,null);
        } else if(this.controller == 1 && this.kind !=0){    //为红子时
            g.drawImage(soldier_r,x,y,null);
        }
        if(this.moveof == 1){
            g.drawImage(point,x+10,y+10,null);
        }
    }

    @Override
    public void movingRange(Qiece[] qieces, int row, int col) {
        if (this.controller == 1){
            //上
            if (row*9+col-9 >= 0) {
                if (qieces[row * 9 + col - 9].getKind() != 0) {
                    if (this.controller != qieces[row * 9 + col - 9].controller) {
                        qieces[row * 9 + col - 9].setMoveof(1);
                    }
                } else if (qieces[row * 9 + col - 9].getKind() == 0) {
                    qieces[row * 9 + col - 9].setMoveof(1);
                }
            }
        } else if (this.controller == 0){
            //下
            if (row*9+col+9 < 90) {
                if (qieces[row * 9 + col + 9].getKind() != 0) {
                    if (this.controller != qieces[row * 9 + col + 9].controller) {
                        qieces[row * 9 + col + 9].setMoveof(1);
                    }
                } else if (qieces[row * 9 + col + 9].getKind() == 0) {
                    qieces[row * 9 + col + 9].setMoveof(1);
                }
            }
        }
        if ((this.controller == 1 && row < 5) || (this.controller == 0 && row >= 5)){
            //右
            if (row*9+col+1 < 90) {
                if (qieces[row*9+col+1].getKind() != 0){
                    if (this.controller != qieces[row*9+col+1].controller){
                        qieces[row*9+col+1].setMoveof(1);
                    }
                }else if (qieces[row*9+col+1].getKind() == 0){
                    qieces[row*9+col+1].setMoveof(1);
                }
            }
            //左
            if (row*9+col-1 >= 0) {
                if (qieces[row*9+col-1].getKind() != 0){
                    if (this.controller != qieces[row*9+col-1].controller){
                        qieces[row*9+col-1].setMoveof(1);
                    }
                }else if (qieces[row*9+col-1].getKind() == 0){
                    qieces[row*9+col-1].setMoveof(1);
                }
            }
        }
    }
}